<?php
/**
 * HospitalityInfo plugin class
 *
 * Main class for all taxes manipulations
 * @access 	public
 * @author 	Rob
 * @copyright	ResMania 2009 all rights reserved.
 * @version	1.0
 * @link	http://developer.resmania.com/api
 * @since  	08-2010
 */
class RM_Plugin_Hospitality extends RM_Plugin {
    public function  __construct()
    {
        $this->name = 'Hospitality';
    }

    public function getNode(){
        return null;
    }

    public function getConfigNode(){
        return null;
    }

    public function upgrade(){
        // userdata
        $pluginViewFolderPath = implode(DIRECTORY_SEPARATOR, array(
            RM_Environment::getConnector()->getRootPath(),
            'RM',
            'userdata',
            'plugins',
            $this->name,
            'views',
            'user',
            'scripts',
            'Unit'
        ));


        $mainFolderPath = implode(DIRECTORY_SEPARATOR, array(
            RM_Environment::getConnector()->getRootPath(),
            'RM',
            'userdata',
            'views',
            'user',
            'scripts',
            'Unit'
        ));

        $fileSource1 = implode(DIRECTORY_SEPARATOR, array($pluginViewFolderPath.DIRECTORY_SEPARATOR."details",'hospitality_unitdetails.phtml'));
        $fileDestin1 = implode(DIRECTORY_SEPARATOR, array($mainFolderPath.DIRECTORY_SEPARATOR."details",'hospitality_unitdetails.phtml'));
        $renameStatus1 = rename($fileSource1, $fileDestin1);

        $fileSource2 = implode(DIRECTORY_SEPARATOR, array($pluginViewFolderPath.DIRECTORY_SEPARATOR."details",'hospitality_selectioninfo.phtml'));
        $fileDestin2 = implode(DIRECTORY_SEPARATOR, array($mainFolderPath.DIRECTORY_SEPARATOR."details",'hospitality_selectioninfo.phtml'));
        $renameStatus2 = rename($fileSource2, $fileDestin2);

        $fileSource3 = implode(DIRECTORY_SEPARATOR, array($pluginViewFolderPath.DIRECTORY_SEPARATOR."list",'hospitality_cartbook_btn_list.js'));
        $fileDestin3 = implode(DIRECTORY_SEPARATOR, array($mainFolderPath.DIRECTORY_SEPARATOR."list",'hospitality_cartbook_btn_list.js'));
        $renameStatus3 = rename($fileSource3, $fileDestin3);

        $fileSource4 = implode(DIRECTORY_SEPARATOR, array($pluginViewFolderPath.DIRECTORY_SEPARATOR."list",'hospitality_unitlist.phtml'));
        $fileDestin4 = implode(DIRECTORY_SEPARATOR, array($mainFolderPath.DIRECTORY_SEPARATOR."list",'hospitality_unitlist.phtml'));
        $renameStatus4 = rename($fileSource4, $fileDestin4);

        $fileSource5 = implode(DIRECTORY_SEPARATOR, array($pluginViewFolderPath.DIRECTORY_SEPARATOR."list",'hospitality_prices_list.phtml'));
        $fileDestin5 = implode(DIRECTORY_SEPARATOR, array($mainFolderPath.DIRECTORY_SEPARATOR."list",'hospitality_prices_list.phtml'));
        $renameStatus5 = rename($fileSource5, $fileDestin5);

        $fileSource6 = implode(DIRECTORY_SEPARATOR, array($pluginViewFolderPath.DIRECTORY_SEPARATOR."list",'hospitality_cartbook_butn_list.phtml'));
        $fileDestin6 = implode(DIRECTORY_SEPARATOR, array($mainFolderPath.DIRECTORY_SEPARATOR."list",'hospitality_cartbook_butn_list.phtml'));
        $renameStatus6 = rename($fileSource6, $fileDestin6);

        $fileSource7 = implode(DIRECTORY_SEPARATOR, array($pluginViewFolderPath.DIRECTORY_SEPARATOR."list",'hospitality_crtbknowbtn.phtml'));
        $fileDestin7 = implode(DIRECTORY_SEPARATOR, array($mainFolderPath.DIRECTORY_SEPARATOR."list",'hospitality_crtbknowbtn.phtml'));
        $renameStatus7 = rename($fileSource7, $fileDestin7);
    }

    public function install(){
        parent::install();

        // userdata
        $pluginViewFolderPath = implode(DIRECTORY_SEPARATOR, array(
            RM_Environment::getConnector()->getRootPath(),
            'RM',
            'userdata',
            'plugins',
            $this->name,
            'views',
            'user',
            'scripts',
            'Unit'
        ));
        

        $mainFolderPath = implode(DIRECTORY_SEPARATOR, array(
            RM_Environment::getConnector()->getRootPath(),
            'RM',
            'userdata',
            'views',
            'user',
            'scripts',
            'Unit'
        ));
       
        $fileSource1 = implode(DIRECTORY_SEPARATOR, array($pluginViewFolderPath.DIRECTORY_SEPARATOR."details",'hospitality_unitdetails.phtml'));
        $fileDestin1 = implode(DIRECTORY_SEPARATOR, array($mainFolderPath.DIRECTORY_SEPARATOR."details",'hospitality_unitdetails.phtml'));
        $renameStatus1 = rename($fileSource1, $fileDestin1);
        
        $fileSource2 = implode(DIRECTORY_SEPARATOR, array($pluginViewFolderPath.DIRECTORY_SEPARATOR."details",'hospitality_selectioninfo.phtml'));
        $fileDestin2 = implode(DIRECTORY_SEPARATOR, array($mainFolderPath.DIRECTORY_SEPARATOR."details",'hospitality_selectioninfo.phtml'));
        $renameStatus2 = rename($fileSource2, $fileDestin2);
 
        $fileSource3 = implode(DIRECTORY_SEPARATOR, array($pluginViewFolderPath.DIRECTORY_SEPARATOR."list",'hospitality_cartbook_btn_list.js'));
        $fileDestin3 = implode(DIRECTORY_SEPARATOR, array($mainFolderPath.DIRECTORY_SEPARATOR."list",'hospitality_cartbook_btn_list.js'));
        $renameStatus3 = rename($fileSource3, $fileDestin3);

        $fileSource4 = implode(DIRECTORY_SEPARATOR, array($pluginViewFolderPath.DIRECTORY_SEPARATOR."list",'hospitality_unitlist.phtml'));
        $fileDestin4 = implode(DIRECTORY_SEPARATOR, array($mainFolderPath.DIRECTORY_SEPARATOR."list",'hospitality_unitlist.phtml'));
        $renameStatus4 = rename($fileSource4, $fileDestin4);

        $fileSource5 = implode(DIRECTORY_SEPARATOR, array($pluginViewFolderPath.DIRECTORY_SEPARATOR."list",'hospitality_prices_list.phtml'));
        $fileDestin5 = implode(DIRECTORY_SEPARATOR, array($mainFolderPath.DIRECTORY_SEPARATOR."list",'hospitality_prices_list.phtml'));
        $renameStatus5 = rename($fileSource5, $fileDestin5);

        $fileSource6 = implode(DIRECTORY_SEPARATOR, array($pluginViewFolderPath.DIRECTORY_SEPARATOR."list",'hospitality_cartbook_butn_list.phtml'));
        $fileDestin6 = implode(DIRECTORY_SEPARATOR, array($mainFolderPath.DIRECTORY_SEPARATOR."list",'hospitality_cartbook_butn_list.phtml'));
        $renameStatus6 = rename($fileSource6, $fileDestin6);

        $fileSource7 = implode(DIRECTORY_SEPARATOR, array($pluginViewFolderPath.DIRECTORY_SEPARATOR."details",'hospitality_crtbknowbtn.phtml'));
        $fileDestin7 = implode(DIRECTORY_SEPARATOR, array($mainFolderPath.DIRECTORY_SEPARATOR."details",'hospitality_crtbknowbtn.phtml'));
        $renameStatus7 = rename($fileSource7, $fileDestin7);

        RM_Filesystem::deleteFolder($pluginViewFolderPath);

        if ($renameStatus1 && $renameStatus2 && $renameStatus3 && $renameStatus4 && $renameStatus5 && $renameStatus6) return true;
        return false;
    }

    public function uninstall() {
        parent::uninstall();

        $model = new RM_UnitTypes();
        $type = $model->findByName('Hospitality');

        $unitModel = new RM_Units();
        $unitModel->update(
            array(
                'type_id' => RM_UnitTypes::DEFAULT_TYPE,
                'published' => 0
            ),
            'type_id='.$type->id
        );

        $file1 = implode(DIRECTORY_SEPARATOR, array(
            RM_Environment::getConnector()->getRootPath(),
            'RM',
            'userdata',
            'views',
            'user',
            'scripts',
            'Unit',
            'details',
            'hospitality_unitdetails.phtml'
        ));
        RM_Filesystem::deleteFile($file1);

        $file2 = implode(DIRECTORY_SEPARATOR, array(
            RM_Environment::getConnector()->getRootPath(),
            'RM',
            'userdata',
            'views',
            'user',
            'scripts',
            'Unit',
            'details',
            'hospitality_selectioninfo.phtml'
        ));
        RM_Filesystem::deleteFile($file2);

        $file3 = implode(DIRECTORY_SEPARATOR, array(
            RM_Environment::getConnector()->getRootPath(),
            'RM',
            'userdata',
            'views',
            'user',
            'scripts',
            'Unit',
            'list',
            'hospitality_cartbook_btn_list.js'
        ));
        RM_Filesystem::deleteFile($file3);

        $file4 = implode(DIRECTORY_SEPARATOR, array(
            RM_Environment::getConnector()->getRootPath(),
            'RM',
            'userdata',
            'views',
            'user',
            'scripts',
            'Unit',
            'list',
            'hospitality_unitlist.phtml'
        ));
        RM_Filesystem::deleteFile($file4);

        $file5 = implode(DIRECTORY_SEPARATOR, array(
            RM_Environment::getConnector()->getRootPath(),
            'RM',
            'userdata',
            'views',
            'user',
            'scripts',
            'Unit',
            'list',
            'hospitality_prices_list.phtml'
        ));
        RM_Filesystem::deleteFile($file5);

        $file6 = implode(DIRECTORY_SEPARATOR, array(
            RM_Environment::getConnector()->getRootPath(),
            'RM',
            'userdata',
            'views',
            'user',
            'scripts',
            'Unit',
            'list',
            'hospitality_cartbook_butn_list.phtml'
        ));
        RM_Filesystem::deleteFile($file6);

        $file7 = implode(DIRECTORY_SEPARATOR, array(
            RM_Environment::getConnector()->getRootPath(),
            'RM',
            'userdata',
            'views',
            'user',
            'scripts',
            'Unit',
            'details',
            'hospitality_crtbknowbtn.phtml'
        ));
        RM_Filesystem::deleteFile($file6);
    }
}